home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / VertexG.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-01  |  8.7 KB  |  295 lines

  1. /*
  2. //   (C) COPYRIGHT International Business Machines Corp. 1993
  3. //   All Rights Reserved
  4. //   Licensed Materials - Property of IBM
  5. //   US Government Users Restricted Rights - Use, duplication or
  6. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. //
  8.  
  9. //
  10. // Permission to use, copy, modify, and distribute this software and its
  11. // documentation for any purpose and without fee is hereby granted, provided
  12. // that the above copyright notice appear in all copies and that both that
  13. // copyright notice and this permission notice appear in supporting
  14. // documentation, and that the name of I.B.M. not be used in advertising
  15. // or publicity pertaining to distribution of the software without specific,
  16. // written prior permission. I.B.M. makes no representations about the
  17. // suitability of this software for any purpose.  It is provided "as is"
  18. // without express or implied warranty.
  19. //
  20. // I.B.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  21. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I.B.M.
  22. // BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  24. // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  25. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26. //
  27. // Author:  John Spitzer, IBM AWS Graphics Systems (Austin)
  28. //
  29. */
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #ifdef WIN32
  33. #include <windows.h>
  34. #endif
  35. #include <GL/gl.h>
  36. #include "FuncEnum.h"
  37. #include <malloc.h>
  38.  
  39. /* This will be set by compile time #defines                     */
  40. /* They control the size and functionality of the code generated */
  41. #ifdef FULL_TEXTURE_PATHS
  42.   #define MIN_TEX_DIM 1
  43.  #if defined(GL_SGIS_texture4D)
  44.   #define MAX_TEX_DIM 4
  45.  #elif defined(GL_EXT_texture3D)
  46.   #define MAX_TEX_DIM 3
  47.  #else
  48.   #define MAX_TEX_DIM 2
  49.  #endif
  50. #else
  51.   #define MIN_TEX_DIM 2
  52.   #define MAX_TEX_DIM 2
  53. #endif
  54. #ifdef FULL_COLOR_PATHS
  55.   #define MAX_COLOR_DIM 4
  56. #else
  57.   #define MAX_COLOR_DIM 3
  58. #endif
  59. #ifdef FULL_VERTEX_PATHS
  60.   #define MIN_VERT_DIM 2
  61. #else
  62.   #define MIN_VERT_DIM 3
  63. #endif
  64. #ifdef FULL_FUNCPTR_PATHS
  65.   #define FUNC_PTRS 1
  66. #else
  67.   #define FUNC_PTRS 0
  68. #endif
  69. #ifdef FULL_UNROLL_PATHS
  70.   #define MAX_UNROLL 8
  71. #else
  72.   #define MAX_UNROLL 1
  73. #endif
  74.  
  75. char* visualSuccinct[] = {
  76.     "Idx",
  77.     "RGB"
  78. };
  79.  
  80. char* pntSuccinct[] = {
  81.     "Pf",
  82.     "Pt"
  83. };
  84.  
  85. char* colorSuccinct[] = {
  86.     "n",
  87.     "v",
  88.     "f",
  89. };
  90.  
  91. char* normalSuccinct[] = {
  92.     "n",
  93.     "v",
  94.     "f",
  95. };
  96.  
  97. char* textureSuccinct[] = {
  98.     "n",
  99.     "v"
  100. };
  101.  
  102. char* visualVerbose[] = {
  103.     "CI",
  104.     "RGB"
  105. };
  106.  
  107. char* pntVerbose[] = {
  108.     "NoPtrs",
  109.     "Ptrs"
  110. };
  111.  
  112. char* colorVerbose[] = {
  113.     "NONE",
  114.     "PER_VERTEX",
  115.     "PER_FACET",
  116. };
  117.  
  118. char* normalVerbose[] = {
  119.     "NONE",
  120.     "PER_VERTEX",
  121.     "PER_FACET",
  122. };
  123.  
  124. char* textureVerbose[] = {
  125.     "NONE",
  126.     "PER_VERTEX"
  127. };
  128.  
  129. char* PrintEntry(FILE *fp, int vis, int p, int c, int n, int t, int u, int v, int vd, int cd, int td)
  130. {
  131.     char* funcName = (char*)malloc(64);
  132.     sprintf(funcName,"%s%sC%sN%sT%sU%dV%d_%d%d%d", visualSuccinct[vis], pntSuccinct[p], colorSuccinct[c], normalSuccinct[n], textureSuccinct[t], u, v, vd, cd, td);
  133.     fprintf(fp,"#define FUNCTION %s\n", funcName);
  134.     fprintf(fp,"#define VISUAL %s\n", visualVerbose[vis]);
  135.     if (p) {
  136.         fprintf(fp,"#define FUNCTION_PTRS\n");
  137.     }
  138.     fprintf(fp,"#define COLOR %s\n", colorVerbose[c]);
  139.     fprintf(fp,"#define NORMAL %s\n", normalVerbose[n]);
  140.     fprintf(fp,"#define TEXTURE %s\n", textureVerbose[t]);
  141.     fprintf(fp,"#define UNROLL          %d\n", u);
  142.     fprintf(fp,"#define VERTS_PER_FACET %d\n", v);
  143.     fprintf(fp,"#define VERTEX_DIM %d\n", vd);
  144.     fprintf(fp,"#define COLOR_DIM %d\n", cd);
  145.     fprintf(fp,"#define TEX_DIM %d\n", td);
  146.     fprintf(fp,"#include \"VertexX.c\"\n");
  147.     fprintf(fp,"#undef FUNCTION\n");
  148.     fprintf(fp,"#undef UNROLL\n");
  149.     fprintf(fp,"#undef VERTS_PER_FACET\n");
  150.     fprintf(fp,"#undef VISUAL\n");
  151.     fprintf(fp,"#undef FUNCTION_PTRS\n");
  152.     fprintf(fp,"#undef COLOR\n");
  153.     fprintf(fp,"#undef NORMAL\n");
  154.     fprintf(fp,"#undef TEXTURE\n");
  155.     fprintf(fp,"#undef VERTEX_DIM\n");
  156.     fprintf(fp,"#undef COLOR_DIM\n");
  157.     fprintf(fp,"#undef TEX_DIM\n");
  158.     fprintf(fp,"\n");
  159.     return funcName;
  160. }
  161.  
  162. FILE* OpenSrcFile(int fileNum)
  163. {
  164.     FILE* fp;
  165.     char filename[64];
  166.  
  167.     sprintf(filename, "Vert%02dF.c", fileNum);
  168.     fp = fopen(filename, "w");
  169.     fprintf(fp, "/*\n * File %s generated from VertexG (source file VertexG.c)\n */\n\n", filename);
  170.     fprintf(fp, "#include \"Vert%02dF.h\"\n", fileNum);
  171.     return fp;
  172. }
  173.  
  174. FILE* OpenHeaderFile(int fileNum)
  175. {
  176.     FILE* fp;
  177.     char filename[64];
  178.  
  179.     sprintf(filename, "Vert%02dF.h", fileNum);
  180.     fp = fopen(filename, "w");
  181.     fprintf(fp, "/*\n * File %s generated from VertexG (source file VertexG.c)\n */\n\n", filename);
  182.     return fp;
  183. }
  184.  
  185. #if ((defined(GL_EXT_texture3D) || defined(GL_SGIS_texture4D)) && defined (FULL_TEXTURE_PATHS))
  186.   #define TEX_DIM_BITS 4
  187. #else
  188.   #define TEX_DIM_BITS 2
  189. #endif
  190.  
  191. #define TOTAL_FUNCS TEX_DIM_BITS*2*9*8*2*2*2
  192. #define TOTAL_FILES 2*4*4
  193.  
  194. main()
  195. {
  196.   VertexFile file;
  197.   VertexFunc function;
  198.   int i;
  199.   int vis,p,c,n,t;
  200.   int v,u;
  201.   int vd, cd, td;
  202.   FILE *fp_src, *fp_header, *fp_table;
  203.   char* funcnames[TOTAL_FUNCS];
  204.   char* filenames[TOTAL_FILES];
  205.  
  206.   for (i=0; i<TOTAL_FILES; i++)
  207.     filenames[i] = "0";
  208.  
  209.   fp_table = fopen("VertexX.h", "w");
  210.   fprintf(fp_table, "/*\n * File VertexX.h generated from VertexG (source file VertexG.c)\n */\n\n");
  211.   fprintf(fp_table, "typedef void (*ExecuteFunc)(TestPtr);\n");
  212.  
  213.   for (vis=0;vis<2;vis++) {
  214.     for (c=0;c<3;c++) {
  215.       for (n=0;n<3;n++) {
  216.  
  217.     file.word = 0;
  218.     file.bits.normalData    = n;
  219.     file.bits.colorData     = c;
  220.     file.bits.visual        = vis;
  221.  
  222.         fp_src = OpenSrcFile(file.word);
  223.     filenames[file.word] = (char*)malloc(64);
  224.     sprintf(filenames[file.word], "VertexExecuteTable%02d", file.word);
  225.     fprintf(fp_table, "extern ExecuteFunc %s[];\n", filenames[file.word]);
  226.         fp_header = OpenHeaderFile(file.word);
  227.     fprintf(fp_header, "#include \"Vertex.h\"\n");
  228.     for (i=0; i<TOTAL_FUNCS; i++)
  229.       funcnames[i] = "Noop";
  230.  
  231.         for (p=0;p<=FUNC_PTRS;p++) {
  232.           for (vd=MIN_VERT_DIM;vd<=3;vd++) {
  233.             if (vis==0) { /* Color index */
  234.               for (v=1;v<=9;v++) {
  235.                 for (u=1;u<=MAX_UNROLL;u++) {
  236.                   if (((u%v==0) || (v%u==0)) && ((v==9)?(u==1):1)) {
  237.                     function.word = 0;
  238.                     function.bits.vertsPerFacet = v-1;
  239.                     function.bits.unrollAmount  = u-1;
  240.                     function.bits.textureData   = 0;
  241.                     function.bits.functionPtrs  = p;
  242.                     function.bits.vertexDim     = vd-2;
  243.                     funcnames[function.word] = PrintEntry(fp_src, vis, p, c, n, 0 /* t */, 
  244.                                                     u, v, vd, 0 /* cd */, 0 /* td */);
  245.                     fprintf(fp_header, "void %s(TestPtr);\n", 
  246.                                     funcnames[function.word]);
  247.                   }
  248.                 }
  249.               }
  250.             } else { /* RGB */
  251.               for (t=0;t<2;t++) {
  252.                 for (td=MIN_TEX_DIM;td<=MAX_TEX_DIM;td++) {
  253.                   for (cd=3;cd<=MAX_COLOR_DIM;cd++) {
  254.                     for (v=1;v<=9;v++) {
  255.                       for (u=1;u<=MAX_UNROLL;u++) {
  256.                         if (((u%v==0) || (v%u==0)) && ((v==9)?(u==1):1)) {
  257.                           function.word = 0;
  258.                           function.bits.vertsPerFacet = v-1;
  259.                           function.bits.unrollAmount  = u-1;
  260.                           function.bits.textureData   = t;
  261.                           function.bits.functionPtrs  = p;
  262.                           function.bits.vertexDim     = vd-2;
  263.                           function.bits.colorDim      = cd-3;
  264.                           function.bits.textureDim    = td-1;
  265.                           funcnames[function.word] = PrintEntry(fp_src, vis, p, c, n, t, 
  266.                                                             u, v, vd, cd, td);
  267.                           fprintf(fp_header, "void %s(TestPtr);\n", 
  268.                                           funcnames[function.word]);
  269.                         }
  270.                       }
  271.                     }
  272.                   }
  273.                 }
  274.               }
  275.             }
  276.           }
  277.         }
  278.  
  279.         fclose(fp_src);
  280.     fprintf(fp_header, "void Noop(TestPtr);\n");
  281.     fprintf(fp_header, "typedef void (*ExecuteFunc)(TestPtr);\n");
  282.     fprintf(fp_header, "\nExecuteFunc VertexExecuteTable%02d[] = {\n", file.word);
  283.     for (i=0; i<TOTAL_FUNCS; i++)
  284.       fprintf(fp_header, "    %s,\n", funcnames[i]);
  285.     fprintf(fp_header, "};\n");
  286.         fclose(fp_header);
  287.       }
  288.     }
  289.   }
  290.  
  291.   fprintf(fp_table, "ExecuteFunc* VertexExecuteTableTable[%d];\n", TOTAL_FILES);
  292.   fclose(fp_table);
  293.   return 0;
  294. }
  295.